"""
Case Type   : 问题回归
Case Name   : vacuum_defer_cleanup_age参数有效性校验
Create At   : 2023/02/08
Owner       : cr13
Description :
    1.为参数vacuum_defer_cleanup_age设置非法参数值
    2.清理环境
Expect      :
    1.合理报错
    2.成功
History     :
"""

import os
import unittest
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger


class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.commsh = CommonSH('PrimaryDbUser')

    def test_gs_upgradectl(self):
        text = "step1:为参数vacuum_defer_cleanup_age设置非法参数值 " \
               "expect:合理报错"
        self.log.info(text)
        sql_cmd = f'set vacuum_defer_cleanup_age to 5.1;set ' \
            f'vacuum_defer_cleanup_age to "1dsadas";'
        result = self.commsh.execut_db_sql(sql_cmd)
        self.log.info(result)
        self.assertIn('ERROR:  parameter "vacuum_defer_cleanup_age" cannot '
                      'be changed now', result, '执行失败' + text)
        self.assertIn('ERROR:  syntax error at or near "dsadas"', result,
                      '执行失败' + text)

    def tearDown(self):
        text = '-----step2:清理环境 expect:成功-----'
        self.log.info(text)
        self.log.info('----无需清理环境----')
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
